import { useI18n } from '/@/hooks/web/useI18n';
import { BasicColumn, BasicTableProps, FormProps } from '/@/components/Table';
import { basWarehouseListData } from '/@/api/bas/house/basWarehouse';

const { t } = useI18n('sys.empUser');

const modalProps = {
  title: t('仓库选择'),
};

let status = '';

const searchForm: FormProps = {
  baseColProps: { lg: 6, md: 8 },
  labelWidth: 80,
  schemas: [
    {
      label: t('仓库编码'),
      field: 'whcode',
      component: 'Input',
    },
    {
      label: t('状态'),
      field: 'status',
      component: 'Input',
      show: false,
    },
    {
      label: t('仓库名称'),
      field: 'whname',
      component: 'Input',
    },
  ],
};

const tableColumns: BasicColumn[] = [
  {
    title: t('仓库编码'),
    dataIndex: 'whcode',
    key: 'a.whcode',
    sorter: true,
    width: 100,
    slot: 'firstColumn',
  },
  {
    title: t('仓库名称'),
    dataIndex: 'whname',
    key: 'a.whname',
    sorter: true,
    width: 100,
  },
];

const tableProps: BasicTableProps = {
  api: basWarehouseListData,
  beforeFetch: (params) => {
    if (params.status == '-1') {
      status = '';
      params.status = '';
    } else {
      if (!status) {
        status = params.status;
      } else {
        params.status = status;
      }
    }
    params['isAll'] = true;
    return params;
  },
  columns: tableColumns,
  formConfig: searchForm,
  rowKey: 'whcode',
};

export default {
  modalProps,
  tableProps,
  itemCode: 'whcode',
  itemName: 'whname',
};
